package com.laboratory.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

public class DruidDatasourceTest {


    public static void main(String[] args) {

        try {
            HashMap configMap = new HashMap();
            configMap.put("driverClassName", "com.mysql.jdbc.Driver");
            configMap.put("url" ,"jdbc:mysql://localhost:3306/workman?useUnicode=true&characterEncoding=UTF8");
            configMap.put("password" ,"a123");
            configMap.put("username" ,"root");
            configMap.put("maxActive" ,"20");
            configMap.put("initialSize" ,"1");
            configMap.put("minIdle" ,"1");

            DataSource dataSource = DruidDataSourceFactory.createDataSource(configMap);
            Connection connection = dataSource.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement("select * from t_user where id =?");
            preparedStatement.setLong(1, 1L);
            ResultSet resultSet = preparedStatement.executeQuery();
            boolean next = resultSet.next();


        } catch (Exception e) {
            e.printStackTrace();
        }


    }



}
